package com.zhaopin.file;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import org.apache.commons.io.FileUtils;

import java.io.File;
import java.io.IOException;
import java.io.PrintWriter;
import java.nio.charset.Charset;
import java.nio.charset.StandardCharsets;
import java.util.List;

/**
 * @author Administrator
 * @create 2019-08-30 13:53
 */
public class HandleCompanyJsonToCanPulsar {

    public static void main(String[] args) throws IOException {
        HandleCompanyJsonToCanPulsar handleCompanyJsonToCanPulsar = new HandleCompanyJsonToCanPulsar();
        List<String> list = FileUtils.readLines(new File("E:\\data\\companyNeedToPulsar.json"), StandardCharsets.UTF_8);
        PrintWriter printWriter = new PrintWriter("E:\\data\\cpulsar.json");
        for (String s : list) {
            JSONObject jsonObject = JSON.parseObject(s);
            String orgId = jsonObject.getString("orgid");
            Integer orgIdInteger = Integer.parseInt(orgId);
            //{"rootOrgId":89099867,"data":{"orgId":89099867,"operatorId":715979500}}
            printWriter.println(handleCompanyJsonToCanPulsar.getString(orgIdInteger));
        }
        printWriter.flush();
        printWriter.close();
    }

    public String getString(Integer orgId) {

        JSONObject jsonObject = new JSONObject();
        jsonObject.put("orgId", orgId);
        jsonObject.put("operatorId", 715979500);

        JSONObject jsonObject1 = new JSONObject();
        jsonObject1.put("rootOrgId", orgId);
        jsonObject1.put("data", jsonObject);
        return jsonObject1.toJSONString();


    }
}
